<!DOCTYPE html>
<html lang="en">
<head>
		<title>SKiDL &mdash; SKiDL Meets GPT</title>
		<meta charset="utf-8" />
		<link rel="profile" href="http://gmpg.org/xfn/11" />
		<link rel="stylesheet" type="text/css" href="/skidl/theme/css/style.css" />
		<link rel='stylesheet' id='oswald-css'  href='http://fonts.googleapis.com/css?family=Oswald&#038;ver=3.3.2' type='text/css' media='all' />
		<link rel="preconnect" href="https://fonts.googleapis.com">
		<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
		<link href="https://fonts.googleapis.com/css2?family=Oswald&family=Roboto+Condensed&display=swap" rel="stylesheet">
		<!-- <style type="text/css">
			body.custom-background { background-color: #f5f5f5; }
		</style> -->
		<link rel="alternate" type="application/atom+xml"
			title="SKiDL — Flux Atom"
			href="/skidl/" />
		<!--[if lte IE 8]><script src="/skidl/theme/js/html5shiv.js"></script><![endif]-->
</head>

<body class="home blog custom-background " >
	<div id="container">
		<div id="header">
				<h1 id="site-title"><a href="/skidl"><img src="/skidl/images/banner.png" width="100%"></a></h1>
				<!-- <h1 id="site-title"><a href="/skidl">SKiDL</a></h1> -->
		</div><!-- /#banner -->

		<div id="menu">
			<div class="menu-navigation-container">
				<ul id="menu-navigation" class="menu">
						<li class="menu-item menu-item-type-post_type menu-item-object-page"><a href="https://github.com/devbisme/skidl">Github</a></li>
						<li class="menu-item menu-item-type-post_type menu-item-object-page"><a href="https://github.com/devbisme/skidl/discussions">Forum</a></li>
						<li class="menu-item menu-item-type-post_type menu-item-object-page"><a href="/skidl/category/posts.html">Blog</a></li>
						<li class="menu-item menu-item-type-post_type menu-item-object-page"><a href="/skidl/api/html/index.html">API</a></li>
						<li class="menu-item menu-item-type-post_type menu-item-object-page"><a href="/skidl/">Home</a></li>

				</ul>
			</div> <!--/#menu-navigation-container-->
		</div><!-- /#menu -->

		<div class="page-title">
		</div>

		<div id="contents">

<div class="post type-post status-publish format-standard hentry category-general" id="post">
	<div class="entry-meta">
		<span class="date"><a href="/skidl/skidl-meets-chatgpt-2023-03-23.html">Thu 23 March 2023</a></span>
		/
		<span class="byline"><a href="/skidl/author/dave-vandenbout.html">Dave Vandenbout</a></span>
	</div> <!-- /#entry-meta -->
	<div class="main">
		<h2 class="entry-title">
			<a href="/skidl/skidl-meets-chatgpt-2023-03-23.html" title="Permalink to SKiDL Meets GPT" rel="bookmark">SKiDL Meets GPT</a>
		</h2>
		<div class="entry-content">
			<p>ChatGPT was released late last year, and GPT4 dropped last week.
These large language models (LLMs) offer some intriguing possibilities.
I had a Twitter conversation about them with <a href="https://twitter.com/alexandrosM">@alexandrosM</a> that started like this:</p>
<p><img alt="" src="images/skidl-meets-chatgpt/gpt_twitter_conv_1.png"></p>
<p>So I described the simplest thing I could think of - a voltage divider - and asked
ChatGPT to design one with some basic specs:</p>
<p><img alt="" src="images/skidl-meets-chatgpt/gpt_twitter_conv_2.png"></p>
<p>Its calculations are correct, so then I asked it to describe the divider circuit using SKiDL:</p>
<p><img alt="" src="images/skidl-meets-chatgpt/gpt_twitter_conv_3.png"></p>
<p>ChatGPT made a number of errors:</p>
<ul>
<li>The <code>Circuit()</code> function doesn't take a name string.</li>
<li>You can't define resistors just by appending <code>.R()</code> to a circuit object.</li>
<li>There's not a <code>connect()</code> function for joining pins of parts.</li>
<li>It joined the resistors in series with <code>Vin</code> at the top but failed to connect the bottom resistor to ground.</li>
<li>It also took <code>Vout</code> from the bottom of the divider instead of the junction where the two resistors connect.</li>
</ul>
<p>So, overall, not that good but you can see it's <em>trying</em>.</p>
<p>I was using ChatGPT which is based on GPT3.5, but Alex has access to GPT4 and wanted to try.
I gave him a very generic description of a relay driver:</p>
<p><img alt="" src="images/skidl-meets-chatgpt/gpt_twitter_conv_4.png"></p>
<p>The output from GPT4 is <em>much</em> better:</p>
<p><img alt="" src="images/skidl-meets-chatgpt/gpt_twitter_conv_5.jpeg"></p>
<p>There are a number of mistakes, so we asked GPT4 to correct the most glaring:</p>
<p><img alt="" src="images/skidl-meets-chatgpt/gpt_twitter_conv_6.png"></p>
<p>Now the result is a little better:</p>
<p><img alt="" src="images/skidl-meets-chatgpt/gpt_twitter_conv_7.jpeg"></p>
<p>There are still a few errors, mostly about the parts and libraries it is using:</p>
<p><img alt="" src="images/skidl-meets-chatgpt/gpt_twitter_conv_8.png"></p>
<p>Rather than go any further with GPT4, I took its final output, removed the comments, and then added the relay along with aliases to match the pin names that GPT4 used:</p>
<div class="highlight"><pre><span></span><code><span class="kn">from</span> <span class="nn">skidl</span> <span class="kn">import</span> <span class="n">Part</span><span class="p">,</span> <span class="n">Net</span><span class="p">,</span> <span class="n">generate_schematic</span>

<span class="c1"># skidl.libs is an error. Comment it out.</span>
<span class="c1"># from skidl.libs import skidl</span>

<span class="c1"># Insert relay G5V-1 in place of Relay_SPDT.</span>
<span class="c1"># relay = Part(&quot;Relay&quot;, &quot;Relay_SPDT&quot;, footprint=&quot;Relay:Relay_SPDT&quot;, value=&quot;&quot;)</span>
<span class="n">relay</span> <span class="o">=</span> <span class="n">Part</span><span class="p">(</span><span class="s2">&quot;Relay&quot;</span><span class="p">,</span> <span class="s2">&quot;G5V-1&quot;</span><span class="p">,</span> <span class="n">footprint</span><span class="o">=</span><span class="s2">&quot;Relay:Relay_SPDT&quot;</span><span class="p">,</span> <span class="n">value</span><span class="o">=</span><span class="s2">&quot;&quot;</span><span class="p">)</span>
<span class="c1"># Alias relay pins with the correct names.</span>
<span class="n">relay</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span><span class="o">.</span><span class="n">aliases</span> <span class="o">+=</span> <span class="s2">&quot;A&quot;</span>
<span class="n">relay</span><span class="p">[</span><span class="mi">9</span><span class="p">]</span><span class="o">.</span><span class="n">aliases</span> <span class="o">+=</span> <span class="s2">&quot;K&quot;</span>
<span class="n">relay</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="o">.</span><span class="n">aliases</span> <span class="o">+=</span> <span class="s2">&quot;NC&quot;</span>
<span class="n">relay</span><span class="p">[</span><span class="mi">10</span><span class="p">]</span><span class="o">.</span><span class="n">aliases</span> <span class="o">+=</span> <span class="s2">&quot;NO&quot;</span>
<span class="n">relay</span><span class="p">[</span><span class="mi">5</span><span class="p">]</span><span class="o">.</span><span class="n">aliases</span> <span class="o">+=</span> <span class="s2">&quot;COM&quot;</span>

<span class="c1"># Change transistor library to Transistor_BJT.</span>
<span class="c1"># transistor = Part(&quot;Transistor_NPN&quot;, &quot;TIP120&quot;, footprint=&quot;:&quot;)</span>
<span class="n">transistor</span> <span class="o">=</span> <span class="n">Part</span><span class="p">(</span><span class="s2">&quot;Transistor_BJT&quot;</span><span class="p">,</span> <span class="s2">&quot;TIP120&quot;</span><span class="p">,</span> <span class="n">footprint</span><span class="o">=</span><span class="s2">&quot;:&quot;</span><span class="p">)</span>

<span class="n">diode</span> <span class="o">=</span> <span class="n">Part</span><span class="p">(</span><span class="s2">&quot;Diode&quot;</span><span class="p">,</span> <span class="s2">&quot;1N4007&quot;</span><span class="p">,</span> <span class="n">footprint</span><span class="o">=</span><span class="s2">&quot;DO-41&quot;</span><span class="p">,</span> <span class="n">value</span><span class="o">=</span><span class="s2">&quot;1N4007&quot;</span><span class="p">)</span>

<span class="n">mcu_output_pin</span> <span class="o">=</span> <span class="n">Part</span><span class="p">(</span><span class="s2">&quot;Device&quot;</span><span class="p">,</span> <span class="s2">&quot;R&quot;</span><span class="p">,</span> <span class="n">footprint</span><span class="o">=</span><span class="s2">&quot;R_0805&quot;</span><span class="p">,</span> <span class="n">value</span><span class="o">=</span><span class="s2">&quot;1k&quot;</span><span class="p">)</span>
<span class="n">mcu_output_pin</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">+=</span> <span class="n">transistor</span><span class="p">[</span><span class="s2">&quot;B&quot;</span><span class="p">]</span>

<span class="n">transistor</span><span class="p">[</span><span class="s2">&quot;C&quot;</span><span class="p">]</span> <span class="o">+=</span> <span class="n">relay</span><span class="p">[</span><span class="s2">&quot;K&quot;</span><span class="p">],</span> <span class="n">diode</span><span class="p">[</span><span class="s2">&quot;A&quot;</span><span class="p">]</span>

<span class="n">diode</span><span class="p">[</span><span class="s2">&quot;K&quot;</span><span class="p">]</span> <span class="o">+=</span> <span class="n">relay</span><span class="p">[</span><span class="s2">&quot;A&quot;</span><span class="p">]</span>

<span class="n">gnd</span> <span class="o">=</span> <span class="n">Net</span><span class="p">(</span><span class="s2">&quot;GND&quot;</span><span class="p">)</span>
<span class="n">transistor</span><span class="p">[</span><span class="s2">&quot;E&quot;</span><span class="p">]</span> <span class="o">+=</span> <span class="n">gnd</span>

<span class="n">vcc_12v</span> <span class="o">=</span> <span class="n">Net</span><span class="p">(</span><span class="s2">&quot;VCC_12V&quot;</span><span class="p">)</span>
<span class="n">relay</span><span class="p">[</span><span class="s2">&quot;A&quot;</span><span class="p">]</span> <span class="o">+=</span> <span class="n">vcc_12v</span>

<span class="n">relay_common</span> <span class="o">=</span> <span class="n">Net</span><span class="p">(</span><span class="s2">&quot;COM&quot;</span><span class="p">)</span>
<span class="n">relay_no</span> <span class="o">=</span> <span class="n">Net</span><span class="p">(</span><span class="s2">&quot;NO&quot;</span><span class="p">)</span>
<span class="n">relay_nc</span> <span class="o">=</span> <span class="n">Net</span><span class="p">(</span><span class="s2">&quot;NC&quot;</span><span class="p">)</span>
<span class="n">relay</span><span class="p">[</span><span class="s2">&quot;COM&quot;</span><span class="p">]</span> <span class="o">+=</span> <span class="n">relay_common</span>
<span class="n">relay</span><span class="p">[</span><span class="s2">&quot;NO&quot;</span><span class="p">]</span> <span class="o">+=</span> <span class="n">relay_no</span>
<span class="n">relay</span><span class="p">[</span><span class="s2">&quot;NC&quot;</span><span class="p">]</span> <span class="o">+=</span> <span class="n">relay_nc</span>

<span class="c1"># I added this command to generate a schematic so we can see what GPT created.</span>
<span class="n">generate_schematic</span><span class="p">(</span>
    <span class="n">retries</span><span class="o">=</span><span class="mi">1</span><span class="p">,</span>
    <span class="n">compress_before_place</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span>
    <span class="n">normalize</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span>
    <span class="n">rotate_parts</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span>
    <span class="n">fanout_attenuation</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span>
    <span class="n">draw_placement</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span>
<span class="p">)</span>
</code></pre></div>

<p>Executing the SKiDL code generated the following schematic (I manually added the blue annotation text.):</p>
<p><img alt="" src="images/skidl-meets-chatgpt/relay_driver_schematic.png"></p>
<p>It's essentially correct, about what a first-year engineering student would do.
That may seem underwhelming except:</p>
<ul>
<li>In the span of four months, LLMs progressed from a version (ChatGPT) that couldn't design a voltage divider to one (GPT4) that designed a relay driver.</li>
<li>There's a lot of electronic design knowledge on the web for training, but examples of using SKiDL are sparse. Even so, GPT4 picked up the basics.</li>
<li>The competency of an average first-year engineering student is now available to <em>anyone</em>.</li>
<li>GPT4 was not specifically trained for designing electronic circuits. This is just one of a myriad of competencies, all of which could be brought to bear on the design process.</li>
</ul>
<p>There are many questions to answer just related to designing electronics with LLMs:</p>
<ul>
<li>How do we efficiently give them information about specific parts and libraries?</li>
<li>Can they develop hierarchical designs by generating modules and composing them? (With SKiDL, this would be nearly the same as writing modularized code.)</li>
<li>Can they create plans for testing the circuitry once it's built? (Similar to writing software unit tests, something ChatGPT has already done.)</li>
<li>Many electronic systems include microcontrollers &amp; FPGAs. Can LLMs write embedded and HDL code to implement specified functions while maintaining compatibility with the hardware they've designed? (LLMs have already shown they can write PC and browser-based software from prompts.)</li>
<li>Can they design the mechanical portions of a system, like cases and enclosures? (ChatGPT has been used to write simple OpenSCAD scripts.)</li>
<li>In order to satisfy design objectives, can they write constraint-satisfaction equations for SAT solvers or optimizers and integrate the results back into their design?</li>
<li>By weaving together the capabilities listed above (plus more), can LLMs become a complete integrated development environment for all phases of engineering design that <a href="https://thenewstack.io/oh-the-places-youll-go-when-you-leave-your-ide/">you never have to leave</a>?</li>
</ul>
<p>Interesting times are ahead! Not just in electronic design, but everything else.</p>
		</div> <!--/#entry-content-->
	</div> <!--/#main-->
</div>  <!--/#post-->

		</div>

		<div id="footer">
			<p> </p>
		</div><!-- /#footer -->
	</div><!-- /#container -->
	<div style="display:none"></div>
</body>
</html>